<template>
  <el-form ref="form" :model="form" label-width="160px">
    <el-form-item label="SecretId" prop="tencent_secretid">
      <el-input v-model="form['secretId']"/>
    </el-form-item>
    <el-form-item label="SecretKey" prop="tencent_secrekey">
      <el-input v-model="form['secretKey']"/>
      <el-alert :closable="false" :title="`请到腾讯云控制台“https://console.cloud.tencent.com/vod/callback”配置回调 URL（${form['vodCallbackUrl']}）`" type="info"/>
    </el-form-item>
    <el-divider content="云点播"/>
    <el-form-item label="云点播防盗KEY" prop="vodKey">
      <el-input v-model="form['vodKey']"/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" class="bg-green" @click="submitForm('form')">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import { encryptionString } from '@/utils/validate'
  export default {
    data() {
      return {
        form: {
          'tencent_id': '',
          'tencent_appid': '',
          'tencent_secretid': '',
          'tencent_secrekey': '',
          'vodKey': ''
        },
        formRules: {}
      }
    },
    created() {
      this.getSiteConfig()
    },
    methods: { encryptionString,
      getSiteConfig() {
        const url = '../videoAdmin/setting/getDataList'
        const data = {
          type: 'tencent'
        }
        this.$store.dispatch('GetConnect', { url, data }).then(res => {
          this.form = res.data;
          this.form.carouselStatus = this.form.carouselStatus === 1;
        }).catch(e => {
          this.$message.error(e.msg + ',请刷新或联系管理员')
        })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const url = '../videoAdmin/setting/updateData'
            const data = Object.assign({}, this.form)
            data.carouselStatus = data.carouselStatus ? 1 : 0
            data.type = 'tencent'
            this.$store.dispatch('GetConnect', { url, data }).then(res => {
              this.$message.success(res.msg)
              this.getSiteConfig()
            }).catch(e => {
              this.$message.error(e.msg)
            })
          } else {
            this.$message.error('提交失败,请检查必填项')
          }
        })
      }
    }
  }
</script>

<style lang="scss" type="text/scss" scoped>
  @import '../../../../styles/index.scss';

  .el-form {
    max-width: 900px;
  }
</style>
